package com.tieba.tieba.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.tieba.tieba.entity.User;
import com.tieba.tieba.mapper.UserMapper;
import com.tieba.tieba.service.IUserService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Mht
 * @since 2020-04-08
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IUserService {
    @Autowired
    UserMapper userMapper;
    @Override
    public boolean hasAccountName(String userAccount) {
        EntityWrapper<User> wrapper = new EntityWrapper<>();
        wrapper.eq("user_account", userAccount);
        int user = userMapper.selectCount(wrapper);

        return user == 1;
    }

    @Override
    public boolean hasEmail(String userEmail) {
        EntityWrapper<User> wrapper = new EntityWrapper<>();
        wrapper.eq("user_email", userEmail);
        int user = userMapper.selectCount(wrapper);

        return user == 1;
    }

    @Override
    public boolean saveUser(User user) {
        int flag = userMapper.insert(user);
        return flag == 1;
    }

    @Override
    public boolean checekPassword(User user) {
        user = userMapper.selectOne(user);
        return user != null;
    }
}
